
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Com.Entity;

/**
 *
 * @author DarkGates
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.StringTokenizer;

import oracle.jdbc.pool.OracleDataSource;
//import Login.Login;

//ini aja buat koneksi...
public class Koneksi {

    static Connection conn;
    private static Connection connection;

    public static Connection getDBConnection() throws SQLException, FileNotFoundException, IOException {
        String result[]=Koneksi.openConfigurationFile(new File("db.conf"));

        OracleDataSource ds;
        ds = new OracleDataSource();
        ds.setURL("jdbc:oracle:thin:@"+result[0]+":1521:XE");
        conn = ds.getConnection(result[1], result[2]);
        return conn;
    }

    public static String[] openConfigurationFile(File file) throws FileNotFoundException, IOException {
        FileInputStream input = new FileInputStream(file);
        String teks = new String();
        int c=0;
        while((c=input.read())!=-1){
           teks +=(char) c;
        }

        StringTokenizer tokens = new StringTokenizer(teks,";");
        String result[] = new String[tokens.countTokens()];

        for (int i = 0; i < result.length; i++) {
            result[i]= tokens.nextToken();
        }

        return result;
    }
}
